import { Prisma } from '@prisma/client';
import { BaseDto, BaseQueryDto } from './base.dto';
import { IsDefined, ValidateNested } from 'class-validator';
import { Transform, Type } from 'class-transformer';

export class BankQueryDto extends BaseQueryDto<{}> {
  @IsDefined({ message: '银行类型必填' })
  type: string;
}

export class BankListDto extends BaseQueryDto<Prisma.BankWhereUniqueInput> {}

export class BankCreateDto extends BaseDto<Prisma.BankCreateInput> {}

export class BankRemoveDto {
  @IsDefined({ message: 'ID必填' })
  @Transform(({ value }) => Number(value))
  id: number;
}

export class BankTypeListDto extends BaseQueryDto<Prisma.UnionBankWhereUniqueInput> {}

export class UnionBankItem {
  @IsDefined({ message: '银行名称必填' })
  name: string;

  bank?: string;

  @IsDefined({ message: '联行号必填' })
  code: string;

  province?: string;

  city?: string;
}

export class BankRpaImportDto {
  @ValidateNested({ each: true })
  @Type(() => UnionBankItem)
  rows?: UnionBankItem[];
}
